#ifndef DATETIME_H
#define DATETIME_H

#include <time.h>
#include <string>

using namespace std;

class DateTime
{
public:
    // DateTime();

    /// 获取日期
    static //2020_01_02
    string getData()
    {
        time_t timep;
        time(&timep);
        char tmp[32];
        strftime(tmp, sizeof(tmp), "%Y_%m_%d",localtime(&timep) );
        return tmp;
    }


    /// 获取时刻
    static //16:19:18
    string getClock()
    {
        time_t timep;
        time(&timep);
        char tmp[32];
        strftime(tmp, sizeof(tmp), "%H_%M_%S",localtime(&timep) );
        return tmp;
    }

    /// 获取全部
    static  /// 2019_03_06 16_19_12
    string getFullTime(string fg = " ")
    {
        time_t timep;
        time(&timep);
        char tmp[64];
        string reg = "%Y_%m_%d" + fg + "%H_%M_%S";
        strftime(tmp, sizeof(tmp), reg.c_str(),localtime(&timep) );
        return tmp;
    }

};

#endif // DATETIME_H
